package com.minelx.datamicroscope.launch;

import com.minelx.datamicroscope.core.JobRunner;
import com.minelx.datamicroscope.core.NewTaskDealer;
import com.minelx.woods.data.Tasks;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import io.gitee.minelx.filesystem.Directory;
import io.gitee.minelx.filesystem.init.OpenPolicy;
import io.gitee.minelx.filesystem.provider.FS;
import org.bson.Document;

public class JobRunnerTest {

	public static final Directory DOWNLOADING_DIRECTORY =
			FS.local().dir("/E:/woods_downloading_directory", OpenPolicy.CREATE_IF_NOT_EXISTED);

	public static void main(String[] args) throws InterruptedException {
		try (MongoClient client = new MongoClient()) {
			MongoDatabase database = client.getDatabase("woods_db");
			MongoCollection<Document> tasksCollection = database.getCollection("tasks");
			Tasks tasks = new Tasks(tasksCollection);

			// run synchronized
			JobRunner jobRunner = new JobRunner(tasks, new NewTaskDealer(DOWNLOADING_DIRECTORY));
			//noinspection InfiniteLoopStatement
			while (true) {
				jobRunner.run();
				//noinspection BusyWait
				Thread.sleep(10000);
			}
		}
	}
}
